import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/Login.vue";
import Layout from "../layout/Index.vue";
import User from "../views/User.vue";
import Fun from "../views/Fun.vue";
import Analysis from "../views/Analysis.vue";
import Role from "../views/Role.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/layout",
    name: "Layout",
    component: Layout,
    redirect: "/setting",
    children: [
      {
        path: "/user",
        component: User,
      },
      {
        path: "/fun",
        component: Fun,
      },
      {
        path: "/analysis",
        component: Analysis,
      },
      {
        path: "/role",
        component: Role,
      },
      // {
      //   path: "/file",
      //   component: File,
      // },
    ],
  },
];

const router = new VueRouter({
  routes,
});

// router.beforeEach((to, from, next) => {
//   let token = Cookies.get('token');
//   if (to.name != 'Login') {
//     if (token) {
//       next();
//     } else {
//       next({
//         path: '/login'
//       });
//     }
//   } else {
//     if (token) {
//       next({
//         path: '/User'
//       });
//     } else {
//       next();
//     }
//   }
// })

export default router;
